package com.huayun.plugin.fastenerLibrary.controller;

import com.huayun.plugin.fastenerLibrary.domain.FastenerLibrary;
import com.huayun.plugin.fastenerLibrary.service.FastenerLibraryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/fastenerLibrary")
public class FastenerLibraryController {

    @Autowired
    private FastenerLibraryService fastenerLibraryService;

    public FastenerLibraryController(FastenerLibraryService fastenerLibraryService) {
        this.fastenerLibraryService = fastenerLibraryService;
    }

    @PostMapping("/attributesImport")
    public ResponseEntity<?> importPropertyFile(@RequestParam MultipartFile file) {
        boolean res = fastenerLibraryService.importPropertyFile(file);
        if(res){
            return ResponseEntity.status(200).body(null);
        }
        return ResponseEntity.status(500).body(null);
    }
    @PostMapping("/getAllPartInfoList")
    public ResponseEntity<?> getAllPartInfoList(@RequestParam String PartNumber) {
        List<FastenerLibrary> fastenerInfoList = fastenerLibraryService.getPartInfo(PartNumber);
        if(fastenerInfoList.size() > 0){
            return ResponseEntity.status(200).body(fastenerInfoList);
        }
        return ResponseEntity.status(500).body(null);
    }



}

